import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      component: () => import("../pages/home/Index.vue"),
      children: [
        {
          path: "/home",
          redirect: "/home/main",
        },
        {
          path: "/home/main",
          component: () => import("../pages/home/main/Index.vue"),
        },
        {
          path: "/home/classify",
          component: () => import("../pages/home/classify/Index.vue"),
        },
        {
          path: "/home/cart",
          component: () => import("../pages/home/cart/Index.vue"),
          meta: {},
        },
        {
          path: "/home/mine",
          component: () => import("../pages/home/mine/Index.vue"),
          meta: {},
        },
      ],
    },
    {
      path: "/address",
      component: () => import("../pages/address/Index.vue"),
    },
    {
      path: "/detail/:id",
      component: () => import("../pages/detail/Index.vue"),
    },
    {
      path: "/login",
      component: () => import("../pages/login/Index.vue"),
    },
    {
      path: "/personinfo",
      component: () => import("../pages/personInfo/Index.vue"),
    },
    {
      path: "/tags/:id",
      component: () => import("../pages/tags/Index.vue"),
    },
    {
      path: "/:pathMatch(.*)*",
      component: () => import("../pages/notFound/Index.vue"),
    },
  ],
});

router.beforeEach((to, from, next) => {
  // 判断要跳转的页面和是否登录
  // to.meta.xxx
  // localStorage.getItem("token")
  next();
});

export default router;
